﻿using System;
using Nb.Common.Domains;
using Nb.Common.Encrypt;

namespace Nb.LMS.Domains.Manufacturers
{
    public class KeyPair : BaseValueObject
    {
        public KeyPair(string manufacturerCode, string publicKey, string privateKey)
        {
            ManufacturerCode = manufacturerCode;
            PublicKey = publicKey;
            PrivateKey = privateKey;
        }

        public string ManufacturerCode { get; set; }
        public string PrivateKey { get; set; }
        public string PublicKey { get; set; }

        public class KeyPairFactory
        {
            public static KeyPair CreateNew(string manufacturerCode)
            {
                //todo guard
                //if (string.IsNullOrWhiteSpace(manufacturerCode))
                //{
                //    throw new InvalidOperationException("必须指定厂商代码");
                //}

                var cryptoHelper = new MyAsymmetricCryptoHelper(manufacturerCode);
                var keyPair = new KeyPair(manufacturerCode, cryptoHelper.PublicKey, cryptoHelper.PrivateAndPublicKey);
                return keyPair;
            }
        }
    }
}
